'use strict';
 const db = uniCloud.database();

exports.main = async (event, context) => {
  //event为客户端上传的参数
  // console.log('event : ' + event)
  const collection = db.collection('users');
  let user_id=event.user_id;
  let friend_id=event.friend_id;
  let res=await collection.where({"_id":user_id}).get();
  let focused_list=res.data[0].focused_users;
  let index = focused_list.indexOf(friend_id);
    console.log(focused_list);
  focused_list.splice(index,1);
  console.log(focused_list);
  res=await collection.doc(user_id).update({
	  focused_users:focused_list
});

  res=await collection.where({"_id":friend_id}).get();
  let is_focused_list=res.data[0].is_focused_users;
  let index2 = is_focused_list.indexOf(user_id);
  is_focused_list.splice(index2,1);
  res=await collection.doc(friend_id).update({
	  is_focused_users:is_focused_list
	});
  //返回数据给客户端
  return {status:2}
};